package lucene.search
{
	import lucene.index.Term;
	import lucene.query.Query;
	
	public class TermWeight extends Weight
	{
		
		private var _term:Term;
		private var _query:Query;
		private var _reader:IReader;
		
		private var _idf:Number;
		private var _queryWeight;
		
		public function TermWeight(term:Term, query:Query, reader:IReader)
		{
			super(this);
			
			this._term = term;
			this._query = query;
			this._reader = reader;
			
		}
		
		override public function sumOfSquaredWeights():Number
		{
			this._idf = this._reader.getSimilarity().idf([this._term], this._reader);
			
			this._queryWeight = this._idf;// * this._query.getBoost();
			
			return Math.pow(this._queryWeight, 2);
		}
		
		override public function normalize(queryNorm:Number):void
		{
			this._queryNorm = queryNorm;
			this._queryWeight *= queryNorm;
			
			this._value = this._queryWeight * this._idf;
		}
		
	}
}